#pragma once

#include "driver/gpio.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "esp_rom_sys.h"

#define BCD_TO_DEC(X) ((X>>4)*10 + (X&0X0F)) 
#define DEC_TO_BCD(X) (((X/10)<<4) | (X%10))

#define DS1302_CLK          2
#define DS1302_DAT          42
#define DS1302_RST          41



#define DS1302_CLK_L        gpio_set_level(DS1302_CLK,0);
#define DS1302_CLK_H        gpio_set_level(DS1302_CLK,1);

#define DS1302_DAT_L        gpio_set_level(DS1302_DAT,0);
#define DS1302_DAT_H        gpio_set_level(DS1302_DAT,1);

#define DS1302_RST_L        gpio_set_level(DS1302_RST,0);
#define DS1302_RST_H        gpio_set_level(DS1302_RST,1);

typedef struct
{
    uint8_t year;
    uint8_t month;
    uint8_t day;
    uint8_t hour;
    uint8_t minute;
    uint8_t second;
    uint8_t week;
}bsp_time_t;

void ds1302_gpio_init(void);                            // ds1302端口初始化
bsp_time_t DS1302_Read_Time();
void ds1302_set_alltime(bsp_time_t set_time);
